import falcon

from WebBackend.middleware.virtualWorldGate_Chuche import login_require
from WebBackend.store.ConfigurationStore import ConfigurationStore

@falcon.before(login_require)
class UserTypeStatus:
    def __init__(self, cs: ConfigurationStore = None):
        self.config_store = cs

    async def on_get(self, req, resp):
        t = req.params.get('type')
        if t is None:
            raise falcon.HTTPBadRequest(title='请求参数错误：name丢失')
        #############################################
        if t == 'local':
            l1 = self.config_store.get_data_by_key('local_enable', True)
            if l1 == 'yes':
                resp.media = {'status': True}
            else:
                resp.media = {'status': False}
        elif t == 'virtual':
            v1 = self.config_store.get_data_by_key('local_enable', True)
            v2 = self.config_store.get_data_by_key('guest_enable', True)
            v3 = self.config_store.get_data_by_key('pam_service_name', True)
            if v1 == 'yes' and v2 == 'yes' and v3:
                resp.media = {'status': True}
            else:
                resp.media = {'status': False}
        elif t == 'anonymous':
            a1 = self.config_store.get_data_by_key('anonymous_enable', True)
            if a1 == 'yes':
                resp.media = {'status': True}
            else:
                resp.media = {'status': False}
        else:
            raise falcon.HTTPBadRequest(title='请求参数错误：type')

    async def on_post(self, req, resp):
        pass
